home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / prog / dict / seq_test.c < prev    next >
C/C++ Source or Header  |  1994-08-05  |  1KB  |  70 lines

  1. #include <LEDA/sortseq.h>
  2. #include <LEDA/impl/skiplist.h>
  3. #include <LEDA/impl/ab_tree.h>
  4. #include <LEDA/impl/bin_tree.h>
  5.  
  6.  
  7. #if !defined(__TEMPLATE_ARGS_AS_BASE__)
  8. declare3(_sortseq,int,int,skiplist)
  9. declare3(_sortseq,int,int,ab_tree)
  10. declare3(_sortseq,int,int,bin_tree)
  11. #endif
  12.  
  13. void seq_test(sortseq<int,int>& D, int N, int* A, char* name)
  14. { int i;
  15.   float T0 = used_time();
  16.   float T  = T0;
  17.  
  18.   cout << string("%-10s",name);
  19.   cout.flush();
  20.  
  21.   for(i=0; i<N; i++)  D.insert(A[i],0);
  22.   cout << string("%10.2f",used_time(T));
  23.   cout.flush();
  24.  
  25.   for(i=0; i<N; i++)  D.lookup(A[i]);
  26.   cout << string("%10.2f",used_time(T));
  27.   cout.flush();
  28.  
  29.   for(i=0; i<N; i++)  D.del(A[i]);
  30.   cout << string("%10.2f",used_time(T));
  31.  
  32.   cout << string("%10.2f",used_time(T0));
  33.   newline;
  34. }
  35.  
  36.  
  37. main()
  38. {
  39.  
  40.   sortseq<int,int>           RS_SEQ;
  41.  
  42. #if defined(__TEMPLATE_ARGS_AS_BASE__)
  43.   _sortseq<int,int,skiplist> SKIP_SEQ;
  44.   _sortseq<int,int,ab_tree>  AB_SEQ;
  45.   _sortseq<int,int,bin_tree> BIN_SEQ;
  46. #else
  47.   _sortseq(int,int,skiplist) SKIP_SEQ;
  48.   _sortseq(int,int,ab_tree)  AB_SEQ;
  49.   _sortseq(int,int,bin_tree) BIN_SEQ;
  50. #endif
  51.  
  52.  
  53.   int     N = read_int("# keys = ");
  54.   int* RAND = new int[N];
  55.  
  56.   for(int i=0; i<N; i++) RAND[i] = random(0,1000000);
  57.  
  58.   newline;
  59.   cout << "               insert    lookup    delete     total";
  60.   newline;
  61.   newline;
  62.  
  63.   seq_test(RS_SEQ,N,RAND,"rs_tree");
  64.   seq_test(SKIP_SEQ,N,RAND,"skiplist");
  65.   seq_test(AB_SEQ,N,RAND,"ab_tree");
  66.   seq_test(BIN_SEQ,N,RAND,"bin_tree");
  67.  
  68.   return 0;
  69. }
  70.